<?php
declare (strict_types = 1);

namespace app\middleware\admin;

class Admin
{
    //忽略登录状态的接口
    protected $ignore_list = [
        'admin/login',
        'admin/logout',
        'admin/captcha',
        '/'
    ];


    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //
        $route = $request->pathinfo();
        if(!in_array($route, $this->ignore_list) && !$request->isOptions()){
            $authorization = $request->header('Authorization');
            $admin = \app\common\model\Admin::checkAuthorization($authorization);
            $request->admin = $admin;
        }
        return $next($request);

    }
}
